<!DOCTYPE html>
<html>
<head>
<#include "/common/freemarker/include_css.ftl">
<title>活动报名</title>
</head>

 
<body>
	<div class="panel panel-default">
	   <div class="panel-heading">
	       <div class="panel-title"><b>${obj.title?if_exists}</b></div>
	   </div>
	   <div clas="panel-body" style="padding:10px">
	      <div class="row">
	           <div class="col-md-12">
	               <br>
	               <form id="contentForm" class="form-horizontal"  action="<@context/>site/event/submitEnroll.do" method="post"  >

						
							<#if enroll?exists>
								<#assign name=enroll.name>
								<#assign qq=enroll.qq>
							<#elseif Session["userlogined"]?exists>
								<#assign name=Session["userlogined"].name>
								<#assign qq=Session["userlogined"].qq?if_exists>
							</#if>
		                    <div class="form-group">
		                    	<label class="col-md-2 control-label">姓名 <font color="red"> *</font></label>
		                        <div class="col-md-9">
									<input type="text"  class="input-sm form-control required" id="name" name="name" value='${name?if_exists}'    minlength="2"  />
		                    	</div>              	
		                    </div>
		                    <div class="form-group">
		                    	<label class="col-md-2 control-label">QQ <font color="red"> *</font></label>
		                        <div class="col-md-9">
									<input type="text"  class="input-sm form-control required" id="qq" name="qq" value='${qq?if_exists}'    minlength="2"  />
									
		                    	</div>              	
		                    </div>
		                    <#if obj?exists && obj.subjects?exists && obj.subjects!="">
			                    <div class="form-group">
			                    	<label class="col-md-2 control-label">感兴趣的主题<font color="red"> *</font></label>
			                        <div class="col-md-9">
			                        	<span  class="checkbox i-check">
							      		    <#if obj.subjects?exists>
								      		    <#list obj.subjects?split(",") as sub>
												<input type="checkbox" name="subjectCheck" id="subject_${sub_index}"  value="${sub}"   <#if enroll?exists && enroll.enrollSubjects?exists && (enroll.enrollSubjects?index_of(sub)>=0)>checked</#if>  />${sub}
											 	</#list>
										 	</#if>
										 </span>
			                    	</div>              	
			                    </div>
			                    <input type="hidden" id="enrollSubjects" name="enrollSubjects" value="<#if enroll?exists>${enroll.enrollSubjects?if_exists}</#if>"> 
		                    </#if> 
		                   
		                      <div class="form-group">
		                    	<div class="col-md-offset-2 col-md-10">
		                    		<#if enrollable>
			                    		<input type="button" class="btn btn-sm  btn-primary" id="submitBtn" value="我要报名"/>
			                    		<input type="hidden" id="eventUuid" name="eventUuid" value="${obj.uuid?if_exists}"> 
			                    		<input type="hidden" id="enrollUuid" name="enrollUuid" value="<#if enroll?exists>${enroll.uuid?if_exists}</#if>"> 
			                    		<#if enroll?exists>
			                    			<input type="button" class="btn btn-sm  btn-primary" id="cancelBtn" value="取消报名"/>
			                    		</#if>
			                    		<label><font color="red" id="msgLable"></font></label>
			                    	 <#else>	
			                    	 	<label><font color="red">报名时间已结束</font></label>
		                    		 </#if>
		                    		<#if Session["userlogined"]?exists>
		                    			<input type="button" class="btn btn-sm  btn-default"  value="返  回" onclick="javascript:history.go(-1)"/>
		                    		</#if>
		                    	</div>
		                    </div>
		                    
		                <div class="form-group">
		               		<label class="col-md-2 control-label"><font color="red"></font></label>
		                    <div class="col-md-9" >
								 ${obj.content?if_exists}
							</div>
						</div>	
						
	                </form>     
	        </div>
	    </div>
	</div>
	<#--  公共js  --考虑外网访问速度，减少不必要的js和css
	<#include "/common/freemarker/include_js.ftl">
	-->
    <script src="<@context/>js/bootstrap.min14ed.js?v=3.3.6"></script>
    <script src="<@context/>common/icheck-1.0.2/icheck.js"></script>   <#--选择狂-->

	<!-- 自定义JS -Jquery表单校验中文信息-->
	<script src="<@context/>common/jquery-validate-1.13.0/jquery.validate.min.js"></script>
	<script src="<@context/>common/jquery-validate-1.13.0/jquery.validate.cn.js"></script>
	<script src="<@context/>common/jquery-validate-1.13.0/jquery.metadata.js"></script>
	

	 
	
	<script>
		 $(document).ready(function(){
				  $('input').iCheck({
				 	  checkboxClass : 'icheckbox_square-blue', 
					  radioClass : 'iradio_square-blue', 
					  increaseArea : '20%' 
				  }); 
	    });
	    
		$("#cancelBtn").click(function() {
		      var enrollUuid=$("#enrollUuid").val();
		 	  var data = {'enrollUuid':enrollUuid};
	 		  $.ajax({
		         type:"POST",
		         url: "<@context/>site/event/cancelEnroll.do",
		         data:data,
		         dataType:'json',
		         cache: false,
		         success: function(html){
		               alert("取消报名成功");
		               $("#msgLable").html("取消报名成功");
		               $("#cancelBtn").attr("disabled",true);	
		                $("#submitBtn").attr("disabled",true);	               
		               <#if Session["userlogined"]?exists>
		               		window.location="<@context/>site/event/search.do";
		               </#if>		               
		         },
		         error: function(html){
		               alert(html.message);
		         }
	 		 });
		}) 
		 
		
		$("#submitBtn").click(function() {
		      // alert(1)
			  if(!$("#contentForm").valid()){
			    	 return;
			  }
			 // alert(2)
 			　 <#if obj.subjects?exists && obj.subjects!="">
	 				var enrollSubjects="";
				    $('input[name="subjectCheck"]').each(function() {
					        if ($(this).prop('checked') ==true) {
					        	if (enrollSubjects==""){
					        		enrollSubjects=$(this).val();
					        	}else{
					        		enrollSubjects=enrollSubjects+","+$(this).val();
					        	}
					        }
					});
					
					if (enrollSubjects==""){
						alert("请选择活动主题");
						return false;
					}
					$("#enrollSubjects").val(enrollSubjects);
				</#if>
				
			  //alert(3)
	    	  var data = $("#contentForm").serialize();
	 		  $.ajax({
		         type:"POST",
		         url: "<@context/>site/event/submitEnroll.do",
		         data:data,
		         dataType:'json',
		         cache: false,
		         success: function(html){
		               alert("报名成功");
		               $("#msgLable").html("报名成功");
		               $("#cancelBtn").attr("disabled",true);	
		                $("#submitBtn").attr("disabled",true);	   
		               <#if Session["userlogined"]?exists>
		               		window.location="<@context/>site/event/search.do";
		               </#if>
		         },
		         error: function(html){
		               alert(html.message);
		         }
	 		 });
	 		 
		})
	</script>
</body>
</html>
<#if  Session["userlogined"]?exists || Session["openid"]?exists>
<#else>	    
</#if>           